package com.blockchain.nodes.web.controller.manager;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.blockchain.nodes.manager.service.IAccountAddressService;

/**
 */
@Controller
@RequestMapping("/node")
public class NodeController 
{
	private static final Logger L = LoggerFactory.getLogger(NodeController.class);
	@Autowired
	private IAccountAddressService accountAddressService;

    /**
	 * 接收底层钱包变化
	 * 1、接收到BTC时
     * 2、发送BTC时 
	 * 3、一个确认的时候
	 * @param txJson
	 * @return
	 */
	@RequestMapping(value = "/walletChanged/{nodeId}/{txId}", method = RequestMethod.GET)
	public void  walletChanged(@PathVariable("nodeId")Integer nodeId,@PathVariable("txId")String txId)  {
		try {
			if(StringUtils.isNotBlank(txId)&&StringUtils.isNotEmpty(txId)) {
				L.info("Wallet transaction changed nodeId:{}  txid:{}",nodeId, txId);
				accountAddressService.walletChange(nodeId,txId);
			}
		} catch (Exception e) {
			L.error("处理底层钱包变化异常：" + e.getMessage());
		}
	}
}
